package com.rabbitmq.demo.dlx;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile(value = "dlx")
@Configuration
public class RabbitMQDLXConfig {

    @Bean
    public DirectExchange dlxDirectExchange(){
        return new DirectExchange("dlx.exchange");
    }

    @Bean
    public Queue dlxQueue(){
        return new Queue("dlx.queue");
    }

    @Bean
    public Binding dlxBinding(DirectExchange dlxDirectExchange,Queue dlxQueue){
        return BindingBuilder.bind(dlxQueue).to(dlxDirectExchange).withQueueName();
    }

    @Profile(value="receiver")
    @Bean
    public Receiver receiver(){
        return new Receiver();
    }
}
